﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using System.Data.SqlClient;
namespace DAO
{
    public class NhanVienDAO:DataProvider
    {
        

        public bool KiemTraDangNhap(string manv, string mk)
        {
            int kq = 0; ;
            connect();

            SqlCommand cmd = new SqlCommand("Select * from NhanVien where ma_nhan_vien= '" + manv + "' and mat_khau='" + mk + "' ", connection);
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                kq++;
            }
            disconnect();
            if (kq == 1)
                return true;
            return false;            
        }

        public NhanVienDTO GetThongTinNhanVien(string manv)
        {
            connect();
            NhanVienDTO nv = new NhanVienDTO();
            SqlCommand cmd = new SqlCommand("Select * from NhanVien where ma_nhan_vien= '"+ manv+"'", connection);
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                nv.NHANVIENID = reader.GetInt32(0);
                nv.MANHANVEN = reader.GetString(1);
                nv.TENNHANVIEN = reader.GetString(3);
                nv.NGAYSINH = reader.GetDateTime(4);
                nv.GIOITINH = reader.GetString(5);
                nv.DIACHI = reader.GetString(6);
                nv.DIENTHOAI = reader.GetString(7);
                nv.LOAINHANVIEN = reader.GetInt32(8);

            }
            disconnect();
            return nv;
        }
    }
}
